require 'erb'
require 'common/base'

$seq_num = nil

class TCPBase < Base

  attr_accessor :step, :transport, :base_options, :base_transports, :base_variables, :message

  def initialize(step, filename, params = {}, transport="xport")
    super()
    @transport = transport
    @step = step

    @base_options = '
     $sport = 52821
     $dport = 80
     $opt_type = 2
     $opt_value = "\x05\xb4"
    '

    @base_variables = '@seq = random_integer(4)'

    @base_transports = 'xport = ip(protocol: 6)'

    if !filename.nil?
      template = get_message("TCP", filename)
      erb = ERB.new(template, 0, '%<>')
      @message = erb.result(binding)

      # save captured variable
      if @message.include?("@server_seq_num = uint(32:32)")
          set_seq_num_call("TCP_Client_Receive_#{@step}")
      end
    end
  end

  def set_seq_num_call(seq)
    $seq_num = seq unless !$seq_num.nil?
  end

  def get_seq_num_call
    return $seq_num
  end

end
